<?php
include('ganon.php');

if(!isset($_GET["imdb"])){
	exit("unable to open file ");
}
$imdbId = $_GET["imdb"];
$aContext  = array(
    'http' => array(
        'proxy' => 'web-proxy.isr.hp.com:8080',
        'request_fulluri' => true
    )
);

$cxContext = stream_context_create($aContext);
$string="http://www.imdb.com/title/".$imdbId."/episodes/_ajax?year=".date('Y');
$file = @file_get_contents($string,  false, $cxContext);
// @file_get_dom("http://www.imdb.com/title/".$imdbId."/episodes/_ajax?year=".date('Y'), true, false, $cxContext);
if($file === FALSE) { 
	exit("unable to open filez ");
}
$series = array();

$html = str_get_dom($file);

foreach ($html('div.list_item') as $element) {
	$show = array();
	$date = $element('.airdate', 0)->getPlainText();
	$show['airdate']=strtotime($date);
	$seasonEpisode = $element('.hover-over-image div', 0)->getPlainText();
	preg_match_all('/\d+/', $seasonEpisode, $matches);
	//$show['season'] = $matches[0][0];
	//$show['episode'] = $matches[0][1];
	array_push($series, $show);
}
header('Content-Type: application/json');
echo json_encode($series);
?>